﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace StateMachineXNA
{
    class StateGame : IGameState
    {
        private SpriteFont font;
        private Vector2 position;
        private float rotation;
        private Timer timer;
        private Texture2D texture;
        private int sidebarWidth = 144;

        public StateGame(Vector2 position, double timer)
        {
            this.position = position;
            this.timer = new Timer(Math.PI, timer);
            rotation = 0;
        }

        public void Init(Game1 game)
        {
            if (font == null) font = game.Content.Load<SpriteFont>("Font");
            texture = game.Content.Load<Texture2D>("GameThumbnail");
        }

        public void Pause()
        { }

        public void Resume()
        { }

        public void Update(StateMachine<IGameState> sm, GameTime gt)
        {
            if (timer.Increment(gt.ElapsedGameTime.TotalSeconds))
            timer.Restart(true);

            rotation = (float)Math.Cos(timer.ElapsedTime * 8) * 0.3f;

            if (Input.KeyPressed(Keys.Escape))
                sm.Pop();
            else if (Input.KeyPressed(Keys.Tab))
                sm.Push(new StatePauseMenu(this));
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(texture, new Vector2(200, 200), Color.Blue);
            sb.Draw(texture, new Rectangle(300, 300, 32, 32), Color.Green);
            sb.Draw(texture, new Rectangle(1000 - sidebarWidth, 0, sidebarWidth, 600), Color.White);
        }
    }
}
